﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WGLGridView;
using DBAccessor.Accessor;
using AlanUtilities;
using DBList.Entities;
using DBList;
using System.Collections.Generic;

public partial class LiJuanTotalTJ : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		String strUID = OperateControl.PickupAvaiableUserID(this);
		if (!IsPostBack)
		{
			int nUID;
			int.TryParse(strUID, out nUID);
			MemberAccessor memberSystem = new MemberAccessor();
			UserData usrData = memberSystem.GetMemberInfo(nUID);
			if (usrData.GroupId != 1 && usrData.GroupId != 2)
			{
				Session[@"LogUserId"] = null;
				OperateControl.PickupAvaiableUserID(this);
				return;
			}
			operaterLabel.Text = strUID;

			BindGrideView();
		}
	}
	private	string	GetYearPriorTwoNumbers()
	{
		string	strYear = tbYear.Text.Trim();
		DateTime	dt;
		if (strYear.Length == 4){
			strYear = strYear.Substring(2, 2);
		}
		else if(DateTime.TryParse(strYear, out dt)){
			strYear = dt.Year.ToString();
			if(strYear.Length >= 4){
				strYear = strYear.Substring(2, 2);
			} 
			else {
				strYear = DateTime.Now.Year.ToString().Substring(2, 2);
			}
		}
		else {
			strYear = DateTime.Now.Year.ToString().Substring(2, 2);
		}
		return strYear;
	}
	private void ShowEmptyRecord()
	{
		string[] fields = { "KindName", "SingleMoney", "TotalNumber", "TMCurrency", "SentNumber", "SMCurrency", "UsedNumber", "UMCurrency", "KindID" };
		WGLGridView.WGLGridView.ClearAndShowEmptyGridView(GridView1, fields);
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onclick", "GridView_selectRow(this)");
			e.Row.Height = 25;
		}
		else if (e.Row.RowType == DataControlRowType.Header)
		{
			e.Row.Height = 25;
		}
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		BindGrideView();
	}
	private void BindGrideView()
	{
		string strYear = GetYearPriorTwoNumbers();
		int nOpeID = int.Parse(operaterLabel.Text);

		CPNAccessor pnaAcce = new CPNAccessor();
		List<LJTJItemData> listData = pnaAcce.LiJuanTotalTJ(nOpeID, strYear);
		GridView1.DataSource = listData;
		if (listData.Count == 0)
		{
			ShowEmptyRecord();
		}
		else
		{
			GridView1.DataBind();
		}
	}
}
